
# import requests



# https://quote.eastmoney.com/center/gridlist.html#hs_a_board

# page = 1
# url = f"https://push2.eastmoney.com/api/qt/clist/get?np={page}&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn=1&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762236624862"
# headers = {
#     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/000000000 Safari/537.36",
#     "Referer": "https://quote.eastmoney.com/center/gridlist.html",
#     "cookie":"fullscreengg=1; fullscreengg2=1; qgqp_b_id=9119a0383d47d6df7f2048baa4fa97e0; st_nvi=LTYdUWa5CkABPMqZ1wGTVece1; st_si=89316110272084; st_pvi=94288366533383; st_sp=2025-11-04%2014%3A03%3A56; st_inirUrl=; st_sn=1; st_psi=20251104140356373-113200301321-5305327857; st_asi=delete; nid=004151a8760615dbad33d559b09d5354; nid_create_time=1762236236810; gvi=43YoDMn9a4pGPaojBvHnre7c7; gvi_create_time=1762236236810"
# }
# res = requests.get(url,headers=headers)
#
# # print(res.status_code)
# data = res.json()
# for item in data['data']['diff']:
#     print(item['f12'], item['f14'])



# 异步协程
# import asyncio
# import aiohttp
#
# page = 1
# url = f"https://push2.eastmoney.com/api/qt/clist/get?np={page}&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn=1&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762236624862"
# headers = {
#     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/000000000 Safari/537.36",
#     "Referer": "https://quote.eastmoney.com/center/gridlist.html",
#     "cookie":"fullscreengg=1; fullscreengg2=1; qgqp_b_id=9119a0383d47d6df7f2048baa4fa97e0; st_nvi=LTYdUWa5CkABPMqZ1wGTVece1; st_si=89316110272084; st_pvi=94288366533383; st_sp=2025-11-04%2014%3A03%3A56; st_inirUrl=; st_sn=1; st_psi=20251104140356373-113200301321-5305327857; st_asi=delete; nid=004151a8760615dbad33d559b09d5354; nid_create_time=1762236236810; gvi=43YoDMn9a4pGPaojBvHnre7c7; gvi_create_time=1762236236810"
# }
#
# async def fetch(session, url):
#     async with session.get(url) as response:
#         data = await response.json()
#         for item in data['data']['diff']:
#             # return item['f12'], item['f14']
#             print(item['f12'], item['f14'])
#
#
# async def main():
#     async with aiohttp.ClientSession(headers=headers) as session:
#         urls = [f"https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={page}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762236624862" for page in range(1,3)]
#         tasks = [fetch(session, url) for url in urls]
#         await asyncio.gather(*tasks)
#         # for data in datas:
#         #     print(data)
#
# asyncio.run(main())


# 线程
import threading

def t_main():
    print(f"线程名：{threading.current_thread().name}")

def main():
    threads = []
    for i in range(1, 3):
        t = threading.Thread(target=t_main,name=f'thread_{i}')
        t.start()
        threads.append(t)

    for t in threads:
        t.join()


if __name__ == '__main__':
    main()


# 线程池
import concurrent.futures
import os
import requests
# print(os.cpu_count())# cpu核心数

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/000000000 Safari/537.36",
    "Referer": "https://quote.eastmoney.com/center/gridlist.html",
    "cookie":"fullscreengg=1; fullscreengg2=1; qgqp_b_id=9119a0383d47d6df7f2048baa4fa97e0; st_nvi=LTYdUWa5CkABPMqZ1wGTVece1; st_si=89316110272084; st_pvi=94288366533383; st_sp=2025-11-04%2014%3A03%3A56; st_inirUrl=; st_sn=1; st_psi=20251104140356373-113200301321-5305327857; st_asi=delete; nid=004151a8760615dbad33d559b09d5354; nid_create_time=1762236236810; gvi=43YoDMn9a4pGPaojBvHnre7c7; gvi_create_time=1762236236810"
}


urls = [f"https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={page}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762236624862" for page in range(1,3)]
def fetch(url):
    res = requests.get(url, headers=headers)
    data = res.json()
    for item in data['data']['diff']:
        print(item['f12'], item['f14'])


with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    for url in urls:
        executor.submit(fetch,url)

    # # 或者
    # futures = [executor.submit(fetch, url) for url in urls]
    # for future in concurrent.futures.as_completed(futures):
    #     print(future.result())





